package com.xbongbong.saas.enums.business;

import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * @author: yingjf
 * @date: 2022/7/7 15:52
 * @description:
 */
public enum OfficePreViewUrlEnum {

    OPTION_1("1","https://view.xbongbong.com/view/url?url="),

    OPTION_2("2","https://view.officeapps.live.com/op/view.aspx?src=")
    ;

    /**
     * code
     */
    private String code;
    /**
     * url
     */
    private String url;


    OfficePreViewUrlEnum(String code, String url) {
        this.code = code;
        this.url = url;
    }

    public static String getCodeByUrl(String url){
        if(StringUtils.isEmpty(url)){
            return null;
        }
        for (OfficePreViewUrlEnum temp: values()){
            if(Objects.equals(temp.url,url)){
                return temp.code;
            }
        }
        return null;
    }


    public static String getUrlByCode(String code){
        if(StringUtils.isEmpty(code)){
            return null;
        }
        for (OfficePreViewUrlEnum temp: values()){
            if(Objects.equals(temp.code,code)){
                return temp.url;
            }
        }
        return null;
    }
    public static String getDefaultUrl(){
        return OPTION_1.url;
    }


}
